# coding=utf-8

import os
import base64

import argparse
import random
import base64

__valid_len = {16, 24, 32}


def make_key(length):
    length = int(length)
    a = os.urandom(length)
    a1 = base64.b64encode(a)
    a2 = a1.decode()
    return a2


if __name__ == "__main__":
    help_msg = r"""
    usage: python aeskey.py --len=16
    len can be {16, 24, 32}
    """
    parser = argparse.ArgumentParser(description=help_msg)
    parser.add_argument('--len', type=int, help=u'Input key length')

    args = parser.parse_args()
    length = args.len
    if length not in __valid_len:
        err = "Valid key len is: {}".format(__valid_len)
        raise ValueError(err)
    key = make_key(args.len)
    print(key)
